class CreateRoles < ActiveRecord::Migration
  def self.up
    say "create role table"
    create_table :roles do |t|
      t.string :label, :null => false
      t.boolean :create_actuality, :null => false, :default => 0
      t.boolean :modify_actuality, :null => false, :default => 0
      t.boolean :delete_actuality, :null => false, :default => 0
      t.boolean :add_product, :null => false, :default => 0
      t.boolean :modify_product, :null => false, :default => 0
      t.boolean :delete_product, :null => false, :default => 0
      t.boolean :add_article, :null => false, :default => 0
      t.boolean :modify_article, :null => false, :default => 0
      t.boolean :delete_article, :null => false, :default => 0
      t.boolean :add_user, :null => false, :default => 0
      t.boolean :modify_user, :null => false, :default => 0
      t.boolean :delete_user, :null => false, :default => 0
      t.boolean :view_store, :null => false, :default => 0
      t.boolean :view_intranet, :null => false, :default => 1
      t.boolean :view_extranet, :null => false, :default => 1

      t.timestamps

    say "update user table to add role field"
    add_column :users, "role_id", :integer, :null => false, :options => "CONSTRAINT fk_roles_users REFERENCES users(id)" 

    end
  end

  def self.down
    drop_table :roles
    remove_column :users, :user_id
  end
end
